<%--
  Created by IntelliJ IDEA.
  User: 田磊
  Date: 2019/10/16 0016
  Time: 11:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%  Integer goodsTypeId=1;
    pageContext.setAttribute("goodsTypeId",goodsTypeId);%>
<c:forEach items="${requestScope.pageInfo.list}" var="g">
    <c:if test="${g.goodsTypeId==1&&g.status==0}">
        <div style="height: 163.2px">
                <%--管理员才看的见--%>
            <c:if test="${sessionScope.user.powers==1}">
                <input type='checkbox' value='${g.id}' name='cks' style='float:left'>
            </c:if>
            <img src="${g.goodsPicture}" alt="history" style="float:left" />
            <div style="float:left">
                <a href="${path}/goodsDetails/list?id=${g.id}">
                    <h5 style="font-weight:bold">${g.goodsName}</h5>
                    <div>
                        <p style="font-weight:bold">${g.goodsDetails}</p>
                    </div>
                </a>
                <p style='float:left;margin-left: -143px'>
                        <%--管理员才看的见--%>
                    <c:if test="${sessionScope.user.powers==1}">
                    <a href='javascript:' func='btnDescription${g.id}' style="color: red">
                        <span class='glyphicon glyphicon-edit'></span></a>
                    </c:if>
                <div class='modal fade' id='myModal2${g.id}' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
                    <div class='modal-dialog'>
                        <div class='modal-content'>
                            <div class='container-flude' style='margin-top: 30px;'>
                                <div class='row'>
                                    <form action='${path}/goods/update?id=${g.id}' method='POST' class='form-horizontal' role='form'
                                          enctype="multipart/form-data" id="update">

                                        <div class='form-group'>
                                            <label class='col-md-4 control-label' style='padding-left:100px'>
                                                &nbsp;&nbsp;&nbsp;用户ID:</label>
                                            <div class='col-md-6' style="margin-top: 8px">
                                                <span style="font-weight: bolder">${g.userId}</span>
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;商品名:</label>
                                            <div class='col-md-6'>
                                                <input type='text' class='form-control' name='goodsName'
                                                       value="${g.goodsName}" placeholder='请输入商品名:例:"优质狗粮"'>
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;选择商品类型:
                                            </label>
                                            <div class='col-md-6'>
                                                <!-- <%--//this指的是选中的select对象--%> -->
                                                <select class='form-control' name='goodsTypeId'>
                                                    <option value="${g.goodsTypeId}">${goodsTypeList[g.goodsTypeId-1].typeName}</option>
                                                    <!-- <%--//商品类型--%> -->
                                                    <c:forEach items="${requestScope.goodsTypeList}" var="t">
                                                        <c:if test="${g.goodsTypeId!=t.id}">
                                                            <option value="${t.id}">${t.typeName}</option>
                                                        </c:if>
                                                    </c:forEach>
                                                </select>
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;商品新旧程度:</label>
                                            <div class='col-md-6'>
                                                <input type='text' class='form-control' name='degree'
                                                       value="${g.degree}" placeholder='请输入商品新旧程度:例:"九成新"'>
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;商品价格:</label>
                                            <div class='col-md-6'>
                                                <input type='text' class='form-control' name='price'
                                                       value="${g.price}" placeholder='请输入商品价格:'>
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商品简介：</label>
                                            <div class='col-md-6'>

                                                                <textarea class='form-control' rows='3'
                                                                          name='goodsDetails'>${g.goodsDetails}</textarea>
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;图片路径:</label>
                                            <div class='col-md-6'>
                                                    <%--<input type='text' class='form-control'--%>
                                                    <%--value="${g.goodsPicture}" name='goodsPicture' placeholder='请输入图片路径:'>--%>
                                                <input type="file" name="goodsPicture" id="myfile" >
                                            </div>
                                        </div>
                                        <div class='form-group'>
                                            <label class='col-md-4 control-label'>&nbsp;&nbsp;&nbsp;所在地:</label>
                                            <div class='col-md-4'style="margin-left: 15px">
                                                <div data-toggle="distpicker">
                                                    <div class="form-group">
                                                        <label class="sr-only" for="province1">Province</label>
                                                        <select class="form-control" name="province" id="province1"></select>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="sr-only" for="city1">City</label>
                                                        <select class="form-control" name="city" id="city1"></select>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="sr-only" for="district1">District</label>
                                                        <select class="form-control" name="district" id="district1"></select>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class='form-group' style="margin-left: 100px">
                                            <div class='col-md-offset-2 col-md-5'style='padding-left:100px'>
                                                <button type='submit' class='btn btn-default'>确认修改</button>
                                                    <%--<button type='button'  class='btn btn-default' id="up">确认修改</button>--%>
                                            </div>
                                        </div>
                                        <br><br><br><br>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                </p>
                <p style="text-align: left;color:red;font-size: 20px;">
                    ¥${g.price}</p>
            </div>
        </div>
        <!-- //弹出服务详情 -->
        <script>$('[func=btnDescription${g.id}]').click(function () {
            var modalInfo = $('#myModal2${g.id}');
            modalInfo.modal();})
        </script>
    </c:if>
</c:forEach>
<%--分页--%>
<div class="container" style="margin-left: 80px;width: 800px;">
    <ul class="pagination"  style="margin-left: 170px">
        <li><a href="javascript:goPage1(1)">首页</a></li>

        <%--上一页--%>
        <c:if test="${pageInfo.pageNum>1}">
            <li><a href="javascript:goPage1(${pageInfo.pageNum-1})">&laquo;</a></li>
        </c:if>
        <c:if test="${pageInfo.pageNum<=1}">
            <li class="disabled"><a>&laquo;</a></li>
        </c:if>

        <!--循环标签显示 - 显示5个
            思路 - 起始值 - 从当前页
        -->
        <%--处理一下最终的页数--%>
        <c:if test="${pageInfo.pages>=3}">
            <c:set var="k" value="2"></c:set>
        </c:if>
        <c:if test="${pageInfo.pages<3}">
            <c:set var="k" value="${pageInfo.pages-1}"></c:set>
        </c:if>

        <c:if test="${pageInfo.pageNum+k<pageInfo.pages}">
            <c:set var="startPage" value="${pageInfo.pageNum}"></c:set>
        </c:if>

        <c:if test="${pageInfo.pageNum+k>=pageInfo.pages}">
            <c:set var="startPage" value="${pageInfo.pages-k}"></c:set>
        </c:if>

        <c:forEach begin="${startPage}" end="${startPage+k}" var="n">
            <%--判断当前页是否高亮显示--%>
            <li <c:if test="${pageInfo.pageNum == n}">class='active'</c:if>> <a href="javascript:goPage1(${n})">${n}</a></li>
        </c:forEach>


        <%--下一页--%>
        <c:if test="${pageInfo.pageNum<pageInfo.pages}">
            <li><a href="javascript:goPage1(${pageInfo.pageNum+1})">&raquo;</a></li>
        </c:if>
        <c:if test="${pageInfo.pageNum>=pageInfo.pages}">
            <li class="disabled"><a>&raquo;</a></li>
        </c:if>

        <li><a href="javascript:goPage1(${pageInfo.pages})">尾页</a></li>
        <li><a href="#">当前页${pageInfo.pageNum}/${pageInfo.pages}总页</a></li>
    </ul>
</div>
<script>
    //    下一页
    function goPage1(pageNum){
        //获取文本框的内容
//        var name = document.getElementById("searchName").value;
        //继续发送类型的数据
//                        var type_id = document.getElementById("").value;
        var goodstypeid=1;
        //发送到后台
        <%--window.location='${path}/goods/list?name='+name+"&goodstypeid="+goodstypeid+"&pageNum="+pageNum;--%>
        //通过ajax的方式进行跳转.
        //原生的js操作ajax
        //原生的jquery$.ajax
        //jquery高级的用法$.get和$.post
        $("#pet_history").load("${path}/goods/list",{goodstypeid:goodstypeid,pageNum:pageNum});
    }
</script>